package DataBase

import (
	"CrudProject/Model"
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

func main() {
	//连接数据库
	db, _ := gorm.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/leotemp?charset=utf8&loc=Local")
	//一个坑，不设置这个参数，gorm会把表名转义后加个s，导致找不到数据库的表
	db.SingularTable(true)
	db.LogMode(true)

	var tcs []Model.TopicClass
	tc := &Model.TopicClass{}
	db.Model(tc).Update(Model.TopicClass{ClassName: "222", ClassRemark: "333"})
	//db.Where("class_name=?","技术").Or(map[string]interface{}{"class_name": "军事"}).Find(&tcs)
	fmt.Println(tcs)
	/*rows, _ := db.Raw("select id,className from class").Rows()
	for rows.Next(){
		var id int
		var name string
		rows.Scan(&id,&name)
		fmt.Println(id,name)
	}*/
	defer db.Close()
}
